package ch02 {
	/**
	 * 追捕行为
	 * 这次要创建三辆机车。一个是只顾移动的机车，其作为目标，
	 * 另外两个转向机车，一个用寻找行为，一个用追捕行为。
	 * 如果一切正常，追捕者靠着优越的算法会胜出。
	 * @author jianping.shenjp
	 */
	import ch02.com.foed.SteeredVehicle;
	import ch02.com.foed.Vector2D;
	import ch02.com.foed.Vehicle;
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;

	public class PursueTest extends Sprite {
		private var _seeker:SteeredVehicle;
		private var _pursuer:SteeredVehicle;
		private var _target:Vehicle;

		public function PursueTest(){
			stage.align = StageAlign.TOP_LEFT;
			stage.scaleMode = StageScaleMode.NO_SCALE;
			_seeker = new SteeredVehicle(0xFF0000);
			_seeker.x = 400;
			addChild(_seeker);
			_pursuer = new SteeredVehicle(0x00FF00);
			_pursuer.x = 400;
			addChild(_pursuer);
			_target = new Vehicle();
			_target.position = new Vector2D(200, 300);
			_target.velocity.length = 10;
			addChild(_target);
			addEventListener(Event.ENTER_FRAME, onEnterFrame);
		}

		private function onEnterFrame(event:Event):void {
			_seeker.seek(_target.position);
			_seeker.update();
			_pursuer.pursue(_target);
			_pursuer.update();
			_target.update();
		}
	}

}